Skip to content

Comments

refactor: impersonation routes to use userId instead of usernames#2455

Merged
prakashchoudhary07 merged 3 commits intoRealDevSquad:developfrom
Suvidh-kaushik:fix/remove_username_from_impersonation_collection
Jul 3, 2025
Merged

refactor: impersonation routes to use userId instead of usernames#2455
prakashchoudhary07 merged 3 commits intoRealDevSquad:developfrom
Suvidh-kaushik:fix/remove_username_from_impersonation_collection

Conversation

@Suvidh-kaushik
Copy link
Contributor

@Suvidh-kaushik Suvidh-kaushik commented Jul 1, 2025

Date: 01/07/2025

Developer Name: Suvidh Kaushik


Issue Ticket Number

Description

  • This PR removes storing the of usernames while creating impersonation requests
  • It modifies the fields userId and impersonatedUserId to createdBy and createdFor
  • It also modifies the GET route to fetch the requests using the latest userId based createdBy and createdFor instead of the original username based filtering
  • The updated API contract - API

Documentation Updated?

  • Yes
  • No

Under Feature Flag

  • Yes
  • No

Database Changes

  • Yes
  • No

Breaking Changes

  • Yes
  • No

Development Tested?

  • Yes
  • No

Screenshots

Recordings
created_and_featch_using_id.mp4

Test Coverage

Screenshot 1

Unit Tests

Screenshot 2025-07-01 233833

Screenshot 2025-07-01 233848

Screenshot 2025-07-01 234036

Screenshot 2025-07-01 234055

Integration Tests

Screenshot 2025-07-01 235131

Additional Notes

Design Doc - LINK

PRD - LINK

Note

I'm currently writing a description for your pull request. I should be done shortly (<1 minute). Please don't edit the description field until I'm finished, or we may overwrite each other. If I find nothing to write about, I'll delete this message.

Description by Korbit AI

What change is being made?

Refactor the impersonation routes to use userId identifiers instead of usernames by replacing all instances of impersonatedUserId with createdFor and ensuring consistent usage of createdBy as an identifier for creating users.

Why are these changes being made?

This change is being made to streamline the handling of impersonation requests, improve consistency in the codebase, and enhance security by ensuring user identifiers are used uniformly, as IDs are more reliable and less prone to errors than usernames. This refactoring converts existing logic and validation throughout services, models, and tests to ensure compatibility with the new identifier approach.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description

@coderabbitai
Copy link

coderabbitai bot commented Jul 1, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Summary by CodeRabbit

  • Refactor
    • Updated impersonation request data model to remove the use of createdBy and createdFor fields, consolidating to userId and impersonatedUserId.
    • Adjusted all related queries, filters, and test data to align with the revised field names.
  • Tests
    • Updated test cases and fixtures to reflect the new data model and field names for impersonation requests.

Walkthrough

This change removes the createdBy and createdFor fields from the impersonation request feature across controllers, services, models, types, fixtures, and tests. All relevant code, queries, and type definitions are updated to use userId and impersonatedUserId instead, aligning field names and simplifying data handling.

Changes

File(s) Change Summary
controllers/impersonationRequests.ts, services/impersonationRequests.ts Removed extraction, usage, and passing of createdBy and createdFor in controller/service logic.
models/impersonationRequests.ts Updated query filters to use userId and impersonatedUserId instead of createdBy/createdFor.
types/impersonationRequest.d.ts Removed createdBy and createdFor from exported type definitions.
test/fixtures/impersonation-requests/impersonationRequests.ts Removed createdBy and createdFor from fixture data objects.
test/integration/impersonationRequests.test.ts Updated test data, assertions, and queries to use userId/impersonatedUserId fields.
test/unit/models/impersonationRequests.test.ts Replaced createdBy/createdFor with userId/impersonatedUserId in tests and assertions.
test/unit/services/impersonationRequests.test.ts Removed all references to createdBy in service unit tests.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Controller
    participant Service
    participant Model
    participant Firestore

    Client->>Controller: Create Impersonation Request (userId, impersonatedUserId, reason)
    Controller->>Service: Pass userId, impersonatedUserId, reason
    Service->>Model: Create impersonation request (userId, impersonatedUserId, reason)
    Model->>Firestore: Store request (userId, impersonatedUserId, reason)
    Firestore-->>Model: Success/Failure
    Model-->>Service: Result
    Service-->>Controller: Result
    Controller-->>Client: Response
Loading

Possibly related PRs

Suggested reviewers

  • MayankBansal12
  • iamitprakash
  • AnujChhikara

Poem

A hop and a skip, the fields are now few,
No more "createdBy" or "createdFor" in view.
Just user IDs clear, like a path in the dew,
The code is much lighter—oh what a breakthrough!
🐇✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Suvidh-kaushik Suvidh-kaushik changed the title Refactor/ POST and GET impersonation request endpoints to use user IDs Instead of usernames Refactor/ POST and GET impersonation endpoints to use user IDs instead of usernames Jul 1, 2025
Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've completed my review and didn't find any issues... but I did find this bear.

/  \.-"""-./  \
\    -   -    /
 |   o   o   |
 \  .-'''-.  /
  '-\__Y__/-'
     `---`
Files scanned
File Path Reviewed
types/impersonationRequest.d.ts
models/impersonationRequests.ts
controllers/impersonationRequests.ts
services/impersonationRequests.ts

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

@Suvidh-kaushik Suvidh-kaushik changed the title Refactor/ POST and GET impersonation endpoints to use user IDs instead of usernames Refactor: POST and GET impersonation endpoints to use user IDs instead of usernames Jul 1, 2025
@Suvidh-kaushik Suvidh-kaushik changed the title Refactor: POST and GET impersonation endpoints to use user IDs instead of usernames Refactor: impersonation routes to use userId instead of usernames Jul 2, 2025
@Suvidh-kaushik Suvidh-kaushik changed the title Refactor: impersonation routes to use userId instead of usernames refactor: impersonation routes to use userId instead of usernames Jul 2, 2025
@prakashchoudhary07
Copy link
Contributor

@Suvidh-kaushik Do we need to update index for it?

@prakashchoudhary07 prakashchoudhary07 merged commit cd129fb into RealDevSquad:develop Jul 3, 2025
5 checks passed
@Suvidh-kaushik
Copy link
Contributor Author

@Suvidh-kaushik Do we need to update index for it?

yes sir will raise a ticket with the indexes that need to be deleted and added due to this update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants